//
//  FirendsTableViewCell.m
//  BaiTengIM
//
//  Created by awh on 2019/7/10.
//  Copyright © 2019年 陈传真. All rights reserved.
//

#import "FirendsTableViewCell.h"
#import "LJPerson.h"


@implementation FirendsTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        _cellType=reuseIdentifier;
        if ([reuseIdentifier isEqualToString:@"addfirendCell"]) {
            CGFloat cellHeight=60;
//            _userAvatar=[[UIImageView alloc]initWithFrame:CGRectMake(10, cellHeight/2-20, 40, 40)];
//            [self addSubview:self.userAvatar];
//            _groupAvatar=[[GroupAvatarImage alloc]initWithFrame:CGRectMake(13, cellHeight/2-20, 40, 40)];
//            [self addSubview:self.groupAvatar];
            
            _userName=[[UILabel alloc]init];
//            _userName.frame=CGRectMake(_groupAvatar.right+15,cellHeight/2-15, SCREEN_WIDTH-70, 30);
            _userName.font=[UIFont systemFontOfSize:14];
            _userName.textColor=KHEXCOLOR(@"#666666");
            _userName.textAlignment=0;
            _userName.text=@"";
            [self addSubview:self.userName]
            ;
        }else if ([reuseIdentifier isEqualToString:@"MobileBookVCCell"])
        {
            self.selectionStyle=UITableViewCellSelectionStyleNone;
            CGFloat cellHeight=60;
            _userAvatar=[[UIImageView alloc]initWithFrame:CGRectMake(10, cellHeight/2-20, 40, 40)];
            [self addSubview:self.userAvatar];
            
            _userName=[[UILabel alloc]init];
            _userName.frame=CGRectMake(_userAvatar.right+15,_userAvatar.y+2, SCREEN_WIDTH-150, 20);
            _userName.font=[UIFont systemFontOfSize:16];
            _userName.textColor=KHEXCOLOR(kBlackColor);
            _userName.textAlignment=0;
            _userName.text=@"";
            [self addSubview:self.userName];
            
            
            _nicknameLbl=[[UILabel alloc]init];
            _nicknameLbl.frame=CGRectMake(_userAvatar.right+15,_userName.bottom+1, SCREEN_WIDTH-150, 15);
            _nicknameLbl.font=[UIFont systemFontOfSize:13];
            _nicknameLbl.textColor=KHEXCOLOR(@"#666666");
            _nicknameLbl.textAlignment=0;
            _nicknameLbl.text=@"昵称";
            [self addSubview:self.nicknameLbl];
        
            
            _invitationBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            _invitationBtn.frame=CGRectMake(SCREEN_WIDTH-85, cellHeight/2-17.5, 58, 35);
            _invitationBtn.layer.masksToBounds=YES;
            _invitationBtn.layer.cornerRadius=17.5;
            [_invitationBtn setTitle:@"邀请" forState:UIControlStateNormal];
            [_invitationBtn addTarget:self action:@selector(didSelecdInvitationBtnAction) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:self.invitationBtn];
            
            
        }else if ([reuseIdentifier isEqualToString:@"newFirendCell"])
        {
            
            self.selectionStyle=UITableViewCellSelectionStyleNone;
            CGFloat cellHeight=60;
            _userAvatar=[[UIImageView alloc]initWithFrame:CGRectMake(15, cellHeight/2-20, 40, 40)];
            _userAvatar.layer.masksToBounds=YES;
            _userAvatar.layer.cornerRadius=20;
            [self addSubview:self.userAvatar];
            
            _userName=[[UILabel alloc]init];
            _userName.frame=CGRectMake(_userAvatar.right+15,_userAvatar.y+2, SCREEN_WIDTH-150, 20);
            _userName.font=[UIFont systemFontOfSize:15];
            _userName.textColor=KHEXCOLOR(kBlackColor);
            _userName.textAlignment=0;
            [self addSubview:self.userName];
            
            
            _nicknameLbl=[[UILabel alloc]init];
            _nicknameLbl.frame=CGRectMake(_userAvatar.right+15,_userName.bottom+1, SCREEN_WIDTH-150, 15);
            _nicknameLbl.font=[UIFont systemFontOfSize:11];
            _nicknameLbl.textColor=KHEXCOLOR(@"#AFAFAF");
            _nicknameLbl.textAlignment=0;
            [self addSubview:self.nicknameLbl];
            
            _invitationBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            _invitationBtn.frame=CGRectMake(SCREEN_WIDTH-65, cellHeight/2-11, 44, 22);
            _invitationBtn.titleLabel.font=[UIFont systemFontOfSize:14];
            _invitationBtn.layer.masksToBounds=YES;
            _invitationBtn.layer.cornerRadius=5;
            [_invitationBtn setTitle:@"接受" forState:UIControlStateNormal];
            [_invitationBtn addTarget:self action:@selector(didSelecdAgreedBtnAction) forControlEvents:UIControlEventTouchUpInside];
            _invitationBtn.backgroundColor=KHEXCOLOR(@"#62A5F3");
            [self addSubview:self.invitationBtn];
            
            _liveV=[[UIView alloc]initWithFrame:CGRectMake(15, 59, SCREEN_WIDTH-30, 0.5)];
            _liveV.backgroundColor=KHEXCOLOR(IM_Color_SeparateLine);
            [self addSubview:self.liveV];
            
        }else if ([reuseIdentifier isEqualToString:@"GroupCell"])
        {
            //群聊
            self.selectionStyle=UITableViewCellSelectionStyleNone;
            CGFloat cellHeight=60.f;
            
//            _groupAvatar=[[GroupAvatarImage alloc]initWithFrame:CGRectMake(13, cellHeight/2-20, 40, 40)];
//            [self addSubview:self.groupAvatar];
            
            _userName=[[UILabel alloc]init];
            _userName.frame=CGRectMake(53+13,cellHeight/2-10, SCREEN_WIDTH-150, 20);
            _userName.font=[UIFont systemFontOfSize:15];
            _userName.textColor=KHEXCOLOR(kBlackColor);
            _userName.textAlignment=0;
            _userName.text=@"这是群聊";
            [self addSubview:self.userName];
            
        }else if ([reuseIdentifier isEqualToString:@"startGroupCell"])
        {
            self.selectionStyle=UITableViewCellSelectionStyleNone;
            CGFloat cellHeight=60.f;
            _userAvatar=[[UIImageView alloc]initWithFrame:CGRectMake(10, cellHeight/2-20, 40, 40)];
            _userAvatar.layer.masksToBounds=YES;
            _userAvatar.layer.cornerRadius=20;
            _userAvatar.image=[UIImage imageNamed:@"bg_pyqtx"];
            [self addSubview:self.userAvatar];
            
            _userName=[[UILabel alloc]init];
            _userName.frame=CGRectMake(_userAvatar.right+15,cellHeight/2-10, SCREEN_WIDTH-150, 20);
            _userName.font=[UIFont systemFontOfSize:16];
            _userName.textColor=KHEXCOLOR(kBlackColor);
            _userName.textAlignment=0;
            _userName.text=@"";
            [self addSubview:self.userName];
            _invitationBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            _invitationBtn.frame=CGRectMake(SCREEN_WIDTH-60, cellHeight/2-20, 40, 40);

//            _invitationBtn.frame=CGRectMake(SCREEN_WIDTH-38, cellHeight/2-9, 18, 18);
            [_invitationBtn setImage:[UIImage imageNamed:@"未选中打钩"] forState:UIControlStateNormal];
            [_invitationBtn setImage:[UIImage imageNamed:@"打钩"] forState:UIControlStateSelected];
            _invitationBtn.imageEdgeInsets=UIEdgeInsetsMake(8, 8, 8, 8);
//            _invitationBtn.backgroundColor=[UIColor redColor];
            [_invitationBtn addTarget:self action:@selector(ClickSelectButton:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:self.invitationBtn];

        }else if ([reuseIdentifier isEqualToString:@"bannedCell"])
        {
            
            self.selectionStyle=UITableViewCellSelectionStyleNone;
            CGFloat cellHeight=60;
            _userAvatar=[[UIImageView alloc]initWithFrame:CGRectMake(10, cellHeight/2-20, 40, 40)];
            _userAvatar.layer.masksToBounds=YES;
            _userAvatar.layer.cornerRadius=5;
            [self addSubview:self.userAvatar];
            
            _userName=[[UILabel alloc]init];
            _userName.frame=CGRectMake(_userAvatar.right+15,cellHeight/2-10, SCREEN_WIDTH-150, 20);
            _userName.font=[UIFont systemFontOfSize:18];
            _userName.textColor=KHEXCOLOR(kBlackColor);
            _userName.textAlignment=0;
            [self addSubview:self.userName];
            
            
            _invitationBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            _invitationBtn.frame=CGRectMake(SCREEN_WIDTH-85, cellHeight/2-17.5, 58, 35);
            _invitationBtn.titleLabel.font=[UIFont systemFontOfSize:14];
            _invitationBtn.layer.masksToBounds=YES;
            _invitationBtn.layer.cornerRadius=17.5;
            [_invitationBtn addTarget:self action:@selector(didSelecBannedBtnAction) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:self.invitationBtn];
        }else if ([reuseIdentifier isEqualToString:@"groupManagerCell"])
        {
            
            self.selectionStyle=UITableViewCellSelectionStyleNone;
            CGFloat cellHeight=60.f;
            _userAvatar=[[UIImageView alloc]initWithFrame:CGRectMake(10, cellHeight/2-20, 40, 40)];
            _userAvatar.layer.masksToBounds=YES;
            _userAvatar.layer.cornerRadius=20;
            [self addSubview:self.userAvatar];
            
            _userName=[[UILabel alloc]init];
            _userName.frame=CGRectMake(_userAvatar.right+15,cellHeight/2-10, SCREEN_WIDTH-150, 20);
            _userName.font=[UIFont systemFontOfSize:16];
            _userName.textColor=KHEXCOLOR(kBlackColor);
            _userName.textAlignment=0;
            _userName.text=@"";
            [self addSubview:self.userName];
            _invitationBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            _invitationBtn.frame=CGRectMake(SCREEN_WIDTH-60, cellHeight/2-20, 40, 40);
            [_invitationBtn setImage:[UIImage imageNamed:@"未选中打钩"] forState:UIControlStateNormal];
            [_invitationBtn setImage:[UIImage imageNamed:@"打钩"] forState:UIControlStateSelected];
            [_invitationBtn setImage:[UIImage imageNamed:@"打钩"] forState:UIControlStateDisabled];
            [_invitationBtn addTarget:self action:@selector(ClickSelectButton:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:self.invitationBtn];
        }else if ([reuseIdentifier isEqualToString:@"deleteFriendsGroupCell"])
        {
            self.selectionStyle=UITableViewCellSelectionStyleNone;
            CGFloat cellHeight=60.f;
            _userAvatar=[[UIImageView alloc]initWithFrame:CGRectMake(10, cellHeight/2-20, 40, 40)];
            _userAvatar.layer.masksToBounds=YES;
            _userAvatar.layer.cornerRadius=20;
            [self addSubview:self.userAvatar];
            
            _userName=[[UILabel alloc]init];
            _userName.frame=CGRectMake(_userAvatar.right+15,cellHeight/2-10, SCREEN_WIDTH-150, 20);
            _userName.font=[UIFont systemFontOfSize:16];
            _userName.textColor=KHEXCOLOR(kBlackColor);
            _userName.textAlignment=0;
            _userName.text=@"";
            [self addSubview:self.userName];
            _invitationBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            _invitationBtn.frame=CGRectMake(SCREEN_WIDTH-60, cellHeight/2-20, 40, 40);
            
            //            _invitationBtn.frame=CGRectMake(SCREEN_WIDTH-38, cellHeight/2-9, 18, 18);
            [_invitationBtn setImage:[UIImage imageNamed:@"未选中打钩"] forState:UIControlStateNormal];
            [_invitationBtn setImage:[UIImage imageNamed:@"打钩"] forState:UIControlStateSelected];
            _invitationBtn.imageEdgeInsets=UIEdgeInsetsMake(8, 8, 8, 8);
            //            _invitationBtn.backgroundColor=[UIColor redColor];
            [_invitationBtn addTarget:self action:@selector(ClickSelectButton:) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:self.invitationBtn];
        }else if ([reuseIdentifier isEqualToString:@"selectedCell"])
        {
            self.selectionStyle=UITableViewCellSelectionStyleNone;
            CGFloat cellHeight=60.f;
            _userAvatar=[[UIImageView alloc]initWithFrame:CGRectMake(10, cellHeight/2-20, 40, 40)];
            _userAvatar.layer.masksToBounds=YES;
            _userAvatar.layer.cornerRadius=20;
            [self addSubview:self.userAvatar];
            
            _userName=[[UILabel alloc]init];
            _userName.frame=CGRectMake(_userAvatar.right+15,cellHeight/2-10, SCREEN_WIDTH-150, 20);
            _userName.font=[UIFont systemFontOfSize:16];
            _userName.textColor=KHEXCOLOR(kBlackColor);
            _userName.textAlignment=0;
            _userName.text=@"";
            [self addSubview:self.userName];
        }else if ([_cellType isEqualToString:@"searchCell"])
        {
            _userAvatar =[[UIImageView alloc]initWithFrame:CGRectMake(15, 11.5, 37, 37)];
            _userAvatar.layer.masksToBounds=YES;
            _userAvatar.layer.cornerRadius=18.5;
//            _userAvatar.backgroundColor=[UIColor redColor];
            [self addSubview:self.userAvatar];
            
            _nicknameLbl=[[UILabel alloc]initWithFrame:CGRectMake(_userAvatar.right+10, 22.5, SCREEN_WIDTH-_userAvatar.right, 15)];
            _nicknameLbl.text=@"钢铁家族";
            [self addSubview:self.nicknameLbl];
            
            _contentLbl = [[UILabel alloc]initWithFrame:CGRectMake(_userAvatar.right+10, _nicknameLbl.bottom+5, SCREEN_WIDTH-_userAvatar.right, 15)];
            _contentLbl.text = @"2条相关记录";
            _contentLbl.textColor = [UIColor grayColor];
            _contentLbl.font = kMainFont(12);
            _contentLbl.hidden = YES;
            [self addSubview:self.contentLbl];
            
            _liveV=[[UIView alloc]initWithFrame:CGRectMake(_nicknameLbl.x, 59, SCREEN_WIDTH, 0.5)];
            _liveV.backgroundColor=KHEXCOLOR(IM_Color_SeparateLine);
            [self addSubview:self.liveV];

        }
        
        
    }
    return self;
}
-(void)ClickSelectButton:(UIButton*)sender
{
    self.model.seleoctedState=!sender.selected;
    sender.selected = ! sender.selected;
    if ([self.delegate respondsToSelector:@selector(FirendsTableViewCellWithClickSelecdCell:)]) {
        [self.delegate FirendsTableViewCellWithClickSelecdCell:self];
    }

}
-(void)didSelecBannedBtnAction
{
    
    if ([self.delegate respondsToSelector:@selector(FirendsTableViewCellWithClickSelecdCell:)]) {
        [self.delegate FirendsTableViewCellWithClickSelecdCell:self];
    }
}

- (void)setFriendModel:(NewFriendModel *)friendModel{
        if (![NSObject ldy_isEmpty:[NSString stringWithFormat:@"%ld",friendModel.type_id]]&&friendModel.type_id == 8) {
        _userName.text=friendModel.nickname;
        [_userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,friendModel.head]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            KWeakSelf;
            weakSelf.userAvatar.image = image;
        }];
        _nicknameLbl.text=friendModel.msg;
    }else
    {
        if (friendModel.fnickname) {
            _userName.text=friendModel.fnickname;
        }else{
            _userName.text=friendModel.nickname;
        }
        //    _userAvatar.backgroundColor=[UIColor redColor];
        _nicknameLbl.text=friendModel.applyContent;
        
        NSString * head ;
        if (friendModel.fhead) {
            head = friendModel.fhead;
        }else{
            head = friendModel.head;
        }
        
        [_userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,head]] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
            KWeakSelf;
            weakSelf.userAvatar.image = image;
        }];
        if ([friendModel.isAgree integerValue]) {
            if (friendModel.fnickname) {
                [_invitationBtn setTitle:@"已接受" forState:UIControlStateNormal];
                _invitationBtn.userInteractionEnabled = NO;
            }else{
                _invitationBtn.userInteractionEnabled = NO;
                [_invitationBtn setTitle:@"已添加" forState:UIControlStateNormal];
            }
            
            _invitationBtn.userInteractionEnabled = NO;
            [_invitationBtn setBackgroundColor:[UIColor whiteColor]];
            [_invitationBtn setTitleColor:KHEXCOLOR(@"#AFAFAF") forState:UIControlStateNormal];
        }else{
            _invitationBtn.userInteractionEnabled = YES;
            if (friendModel.fnickname) {
                [_invitationBtn setTitle:@"接受" forState:UIControlStateNormal];
            }else{
                [_invitationBtn setTitle:@"添加" forState:UIControlStateNormal];
            }
            
            _invitationBtn.userInteractionEnabled = YES;
            [_invitationBtn setBackgroundColor:KHEXCOLOR(@"#62A5F3")];
        }
        if ([friendModel.isLocal isEqualToString:@"1"]) {
            _invitationBtn.hidden = YES;
        }else{
            _invitationBtn.hidden = NO;
        }
    }
   
}
- (void)setGroupMerrDelete:(NSInteger)groupMerrDelete{
    _groupMerrDelete = groupMerrDelete;
}

-(void)setModel:(ContactModel *)model
{

    if ([_cellType isEqualToString:@"startGroupCell"]) {
        CGFloat cellHeight=60.f;
         if (_groupMerrDelete == 4) {
             _userAvatar.frame = CGRectMake(10, cellHeight/2-20, 40, 40);
              _invitationBtn.frame=CGRectMake(SCREEN_WIDTH-60, cellHeight/2-20, 40, 40);
              _userName.frame=CGRectMake(_userAvatar.right+15,cellHeight/2-10, SCREEN_WIDTH-150, 20);
             _invitationBtn.hidden=NO;

         }else if (_groupMerrDelete == 5) {
             _userAvatar.frame = CGRectMake(10, cellHeight/2-20, 40, 40);
             _userName.frame=CGRectMake(_userAvatar.right+15,cellHeight/2-10, SCREEN_WIDTH-150, 20);
             _invitationBtn.hidden=YES;
         }else
         {
             _userAvatar.frame = CGRectMake(60, cellHeight/2-20, 40, 40);
             _userName.frame=CGRectMake(_userAvatar.right+15,cellHeight/2-10, SCREEN_WIDTH-150, 20);
             _invitationBtn.frame=CGRectMake(15, cellHeight/2-20, 40, 40);
             _invitationBtn.hidden=NO;

         }
        _userName.text=model.username;
        
        if (_groupMerrDelete == 4) {
            _userName.text = model.remark;
            _invitationBtn.hidden = YES;
            NSString * headUrl = model.head;
            [_userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,headUrl]] placeholderImage:kHeadGroupPlaceholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                           KWeakSelf;
                           weakSelf.userAvatar.image = image;
                           }];
        }else{
                _userName.text=model.nickName;
                _userName.text=model.username;
                _invitationBtn.selected=model.seleoctedState;
        if ([CommonTools isEmpty:model.nickName]) {
            _userName.text=model.nickname;
        }else if ([CommonTools isEmpty:model.nickname]){
            _userName.text = model.nickName;
        }
        if (_groupMerrDelete == 3 || _groupMerrDelete == 5) {
           _userName.text = model.remark;
        }
        NSString * headUrl = model.head;
    [_userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,headUrl]] placeholderImage:kHeadGroupPlaceholderImage completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
                   KWeakSelf;
                   weakSelf.userAvatar.image = image;
                   }];
            
            if (model.seleoctedState) {
                _invitationBtn.userInteractionEnabled = NO;
                
            }else{
                _invitationBtn.userInteractionEnabled = YES;
            }
//                if (_invitationBtn.selected) {
//                    _invitationBtn.userInteractionEnabled=NO;
//                }

//                if ([model.type integerValue]==0) { // 成员
//                    _invitationBtn.hidden= NO;
//                } else if ([model.type integerValue]==1) { // 管理员
//                    _invitationBtn.hidden=YES;
//
//                } else { // 群主
//                    _invitationBtn.hidden=YES;
//
//                }
//                [_userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MainImageURl,model.avatar]] placeholderImage:kHeadPlaceholderImage];
//
//                if ([model.type integerValue]==2) {
//                    _invitationBtn.hidden=YES;
//                }else
//                {
//                    _invitationBtn.hidden=NO;
//                }
        }
        
    }else if ([_cellType isEqualToString:@"searchCell"]){
        _model = model;
        NSString * headUrl;
        if (model.head) {
             headUrl = _model.head;
             _nicknameLbl.text = _model.nickname;
        }else{
             headUrl = _model.groupHead;
             _nicknameLbl.text = _model.groupName;
        }
//        NSData * headData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,headUrl]]];
//        self.userAvatar.image = [UIImage imageWithData:headData];
        [_userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,headUrl]] placeholderImage:[UIImage imageNamed:@"bg_pyqtx"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            KWeakSelf;
            weakSelf.userAvatar.image = image;
            }];
        
    }
    
//    [_userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MainImageURl,model.memberModel.avatar]] placeholderImage:kHeadPlaceholderImage];
//    if ([_cellType isEqualToString:@"newFirendCell"]){
//
//        [_userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MainImageURl,model.avatar]] placeholderImage:kHeadPlaceholderImage];
//
//        NSString*typeTitle;
//        if ([model.type integerValue]==0) {
//            //好友0 群1
//            typeTitle=@"好友申请：";
//            _nicknameLbl.text=[NSString stringWithFormat:@"%@%@申请添加为好友",typeTitle,model.nickName];
//
//        }else{
//            typeTitle=@"群申请：";
////            ContactorModel *group = [[LoginManager shareLoginManager] ReadGroupInfoDataWithGroupID:model.group_id];
//            NSArray * array  =  [model.content componentsSeparatedByString:@",&mObI_"];
//            if (array.count>0) {
//                NSString * groupName=array[0];
//                if (![NSObject ldy_isEmpty:groupName]) {
//                    _nicknameLbl.text=[NSString stringWithFormat:@"%@%@申请加入%@群",typeTitle, model.nickName,groupName];
//                }
//            }
//            BTIMLog(@"content======%@",array);
////      _nicknameLbl.text=[NSString stringWithFormat:@"%@%@",typeTitle, model.nickName];
//        }
//
//        if ([model.is_firend isEqualToString:@"yes"]) {
//            [_invitationBtn setTitle:@"已添加" forState:UIControlStateNormal];
//            [_invitationBtn setTitleColor:KHEXCOLOR(kGrayColor_66) forState:UIControlStateNormal];
//            _invitationBtn.backgroundColor=[UIColor clearColor];
//            _invitationBtn.userInteractionEnabled=NO;
//
//        }else
//        {
//            //            0 待处理 1 同意 2 拒绝
//            if ([model.status integerValue]==2) {
//                [_invitationBtn setTitle:@"已拒绝" forState:UIControlStateNormal];
//                [_invitationBtn setTitleColor:KHEXCOLOR(kGrayColor_66) forState:UIControlStateNormal];
//                _invitationBtn.backgroundColor=[UIColor clearColor];
//                _invitationBtn.userInteractionEnabled=NO;
//            }else if ([model.status integerValue]==1)
//            {
//                [_invitationBtn setTitle:@"已添加" forState:UIControlStateNormal];
//                [_invitationBtn setTitleColor:KHEXCOLOR(kGrayColor_66) forState:UIControlStateNormal];
//                _invitationBtn.backgroundColor=[UIColor clearColor];
//                _invitationBtn.userInteractionEnabled=NO;
//            }else
//            {
//                [_invitationBtn setTitle:@"添加" forState:UIControlStateNormal];
//                _invitationBtn.backgroundColor=KHEXCOLOR(@"#4880F2");
//                [_invitationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//                _invitationBtn.userInteractionEnabled=YES;
//
//            }
//
////            if ([model.type integerValue]==1) {
////                //群
////                if ([model.is_group isEqualToString:@"no"]) {
////                    [_invitationBtn setTitle:@"已过期" forState:UIControlStateNormal];
////                    [_invitationBtn setTitleColor:KHEXCOLOR(kGrayColor_66) forState:UIControlStateNormal];
////                    _invitationBtn.backgroundColor=[UIColor clearColor];
////                    _invitationBtn.userInteractionEnabled=NO;
////
////                }else
////                {
////                    _invitationBtn.userInteractionEnabled=YES;
////
////                }
////            }else
////            {
////                _invitationBtn.userInteractionEnabled=YES;
////
////            }
//        }
//    } else if ([_cellType isEqualToString:@"startGroupCell"]) {
////        _userName.text=model.nickName;
//        _userName.text=model.nickname;
//
//        _invitationBtn.selected=model.seleoctedState;
//        if (_invitationBtn.selected) {
//            _invitationBtn.userInteractionEnabled=NO;
//        }
//
//        if ([model.type integerValue]==0) { // 成员
//            _invitationBtn.hidden= NO;
//        } else if ([model.type integerValue]==1) { // 管理员
//            _invitationBtn.hidden=YES;
//
//        } else { // 群主
//            _invitationBtn.hidden=YES;
//
//        }
//        [_userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MainImageURl,model.avatar]] placeholderImage:kHeadPlaceholderImage];
//
////        if ([model.type integerValue]==2) {
////            _invitationBtn.hidden=YES;
////        }else
////        {
////            _invitationBtn.hidden=NO;
////        }
////
//
//    }else if([_cellType isEqualToString:@"bannedCell"])
//    {
//        _userName.text=model.memberModel.nickName;
//        if ([model.state isEqualToString:@"1"]) {
//            //全体禁言状态
//            [_invitationBtn setTitle:@"解除" forState:UIControlStateNormal];
//            _invitationBtn.backgroundColor=KHEXCOLOR(kGrayColor_f2);
//            [_invitationBtn setTitleColor:KHEXCOLOR(kGrayColor_66) forState:UIControlStateNormal];
//        } else if ([model.state isEqualToString:@"0"])
//        {
//            //全体解禁状态
//            if ([model.status integerValue]==1) {
//
//                [_invitationBtn setTitle:@"解除" forState:UIControlStateNormal];
//                [_invitationBtn setTitleColor:KHEXCOLOR(kGrayColor_66) forState:UIControlStateNormal];
//                            _invitationBtn.backgroundColor=KHEXCOLOR(kGrayColor_f2);
//                }else{
//
//                [_invitationBtn setTitle:@"禁言" forState:UIControlStateNormal];
//                            _invitationBtn.backgroundColor=KHEXCOLOR(@"#4880F2");
//                [_invitationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//            }
//        }
//        if ([model.type integerValue]==1 || [model.type integerValue]==2) {
//            _invitationBtn.hidden=YES;
//        }else
//        {
//            _invitationBtn.hidden=NO;
//        }
//    } else if ([_cellType isEqualToString:@"groupManagerCell"]) {
//        NSString *name = @"";
//        BOOL isFriend = [[LoginManager shareLoginManager].userDataBase isAlreadyHaveUserOrGroupWithID:model.memberModel.user_id.integerValue istype:1];
//        if (isFriend) {
//            ContactorModel *friend = [[LoginManager shareLoginManager].userDataBase ReadFriendDataWithUid:model.memberModel.user_id];
//            name = [NSObject ldy_isEmpty:friend.nickname] ? model.memberModel.nickName : friend.nickname;
//        } else {
//            name = model.memberModel.nickName;
//        }
//        _userName.text=name;
//        if (model.group_role == 1) {
//            _invitationBtn.userInteractionEnabled = NO;
//        } else {
//            _invitationBtn.userInteractionEnabled = YES;
//        }
//        [_userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",MainImageURl,model.memberModel.avatar]] placeholderImage:kHeadPlaceholderImage];
//
//        _invitationBtn.selected= (model.group_role == 1 || model.group_role == 2);
//
//    }
//    else if ([_cellType isEqualToString:@"addfirendCell"])
//    {
//        [_groupAvatar CustomstitchingWithImageUrl:@[[NSString stringWithFormat:@"%@%@",MainImageURl,model.avatar]] margin:2.5 placeholderImage:kHeadPlaceholderImage];
//    }
//    else if ([_cellType isEqualToString:@"deleteFriendsGroupCell"])
//    {
//
//        NSString *name = @"";
//        BOOL isFriend = [[LoginManager shareLoginManager].userDataBase isAlreadyHaveUserOrGroupWithID:model.userId.integerValue istype:1];
//        if (isFriend) {
//            ContactorModel *friend = [[LoginManager shareLoginManager].userDataBase ReadFriendDataWithUid:model.userId];
//            name = [NSObject ldy_isEmpty:friend.nickname] ? model.nickname : friend.nickname;
//        } else {
//            name = model.nickname;
//        }
//        _userName.text= name;
//        _invitationBtn.selected=model.seleoctedState;
//        if (_invitationBtn.selected) {
//            _invitationBtn.userInteractionEnabled=NO;
//        }
//
//        if ([model.type integerValue]==0) { // 成员
//            _invitationBtn.hidden= NO;
//        } else if ([model.type integerValue]==1) { // 管理员
//            _invitationBtn.hidden=NO;
//
//        } else { // 群主
//            _invitationBtn.hidden=YES;
//        }
//    }
//
}
//群信息
#pragma mark- 群的model
-(void)setGroupModel:(ContactModel *)GroupModel
{
    _GroupModel = GroupModel;
           NSString * headUrl = _GroupModel.groupHead;
           [_userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,headUrl]] placeholderImage:[UIImage imageNamed:@"bg_pyqtx"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
               KWeakSelf;
               weakSelf.userAvatar.image = image;
               }];
         
               _nicknameLbl.text = _GroupModel.groupName;
           
//    if ([GroupModel.group_type isEqualToString:@"initData"]) {
//        _userName.text = GroupModel.groupname;
//    }else
//    {
//        _userName.text = GroupModel.groupName;
//
//    }
//    //读取群头像
//    NSArray * array=[[LoginManager shareLoginManager].userDataBase ReadGroupAvatarWithGroupID:[NSString stringWithFormat:@"%@",GroupModel.user_id]];
//    //九宫格 头像边距
//    [_groupAvatar CustomstitchingWithImageUrl:array margin:2.5 placeholderImage:kHeadPlaceholderImage];

}
-(void)setPubModel:(PublicModel *)pubModel
{

  if ([_cellType isEqualToString:@"searchCell"]){
      _pubModel = pubModel;
        NSString * headUrl = pubModel.head;
             _nicknameLbl.text = pubModel.title;

        [_userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,headUrl]] placeholderImage:[UIImage imageNamed:@"bg_pyqtx"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            KWeakSelf;
            weakSelf.userAvatar.image = image;
            }];
        
    }
}

#pragma mark -- 远程搜索群
-(void)setSerachGroupModel:(ContactModel *)serachGroupModel
{
    _userName.text = serachGroupModel.username;
//    [_groupAvatar CustomstitchingWithImageUrl:@[@""] margin:2.5 placeholderImage:kHeadGroupPlaceholderImage];
}
-(void)setSerachLocalDataModel:(ContactModel *)serachLocalDataModel
{
//    if ([serachLocalDataModel.is_group isEqualToString:@"group"]) {
//
//        _userName.text = serachLocalDataModel.groupname;
//        //读取群头像
//        NSArray * array=[[LoginManager shareLoginManager].userDataBase ReadGroupAvatarWithGroupID:[NSString stringWithFormat:@"%@",serachLocalDataModel.user_id]];
//        //九宫格 头像边距
//        [_groupAvatar CustomstitchingWithImageUrl:array margin:2.5 placeholderImage:kHeadPlaceholderImage];
//    }else
//    {
//
//        _userName.text = serachLocalDataModel.nickname;
//        NSString *url = [NSString stringWithFormat:@"%@%@",MainImageURl,serachLocalDataModel.avatar];
//        [_groupAvatar CustomstitchingWithImageUrl:@[url] margin:2.5 placeholderImage:kHeadPlaceholderImage];
//    }
}

- (void)setMessageModel:(BTMessageModel *)messageModel{
    
    NSLog(@"%@",messageModel);
    _messageModel= messageModel;
    
    
    
          _nicknameLbl.text = _messageModel.nickname;
    NSLog(@"头像：%@",_messageModel.head);
    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage,_messageModel.head]]];
    _userAvatar.image = [UIImage imageWithData:data];
    

    
//      if (messageModel.chatType==ChatTypeFriend) { // 单聊
//            // 头像与名称
//            
//            NSInteger friendId = [[messageModel.keyid componentsSeparatedByString:@"_"] lastObject].integerValue;
//
//           ContactModel * rmodel = [[UserDataBaseTool shareUserDataBaseTool]queryFriends:[NSString stringWithFormat:@"%ld", friendId]];
//            self.nicknameLbl.text = rmodel.nickname;
//            [self.userAvatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",userHeaderImage, rmodel.head]] placeholderImage:kHeadPlaceholderImage];
//            // 内容
//            if (messageModel.msgtype == MessageTypeText) {
//                TextMessageModel *textModel = (TextMessageModel *)message;
//                NSString *content = textModel.msg;
//                if (message.searchKeywords) {
//                    self.contentLabel.attributedText = [self highlightText:message.searchKeywords inStr:content];
//                } else {
//                    self.contentLabel.text = content;
//                }
//            } else if (message.msgtype == MessageTypeImage) {
//                self.contentLabel.text = @"[图片]";
//            } else if (message.msgtype == MessageTypeVoice) {
//                self.contentLabel.text = @"[语音]";
//            } else if (message.msgtype == MessageTypeRecall) {
//                self.contentLabel.text = message.messageDirection == MessageDirectionSend ? @"你撤回了一条消息" : @"对方撤回了一条消息";
//            }
//            if (message.type_id == SystemMessageAgreeAddFriend) {
//                self.contentLabel.text = @"你们已成为好友，可以开始聊天啦";
//            }
//
//        } else if (message.chatType == ChatTypeGroup) { // 群聊
//            // 头像与名称
//            NSInteger groupId;
//            if ([NSObject ldy_isEmpty:message.keyid]) {
//                groupId = [message.gId integerValue];
//            }else
//            {
//                groupId = [[message.keyid componentsSeparatedByString:@"_"] lastObject].integerValue;
//            }
//            ContactModel * rmodel = [[UserDataBaseTool shareUserDataBaseTool]queryGroup:[NSString stringWithFormat:@"%ld", groupId]];
//            self.nameLabel.text = rmodel.groupName;
//            if (message.msgtype == MessageTypeText) {
//                TextMessageModel *textModel = (TextMessageModel *)message;
//                BOOL isBlank = [NSObject ldy_isEmpty:textModel.content];
//                NSString *content =  [NSString stringWithFormat:@"%@: %@", message.username, textModel.msg];
//                
//    //            NSString *content = textModel.content;
//                if (message.searchKeywords) {
//                    self.contentLabel.attributedText = [self highlightText:message.searchKeywords inStr:content];
//                } else {
//                    NSArray<NSString *> *components = [content componentsSeparatedByString:kAtDividedSymbols];
//                    if (components.count >= 2) {
//                        content = components[0];
//                    }
//                    self.contentLabel.text = content;
//                    if (isBlank) {
//                        self.contentLabel.text = @"";
//                    }
//                }
//                self.contentLabel.text = content;
//
//            }
    
}

#pragma mark- 手机通讯录
-(void)setMobileModel:(LJPerson *)mobileModel
{
    _userAvatar.image = mobileModel.image ? mobileModel.image : kHeadPlaceholderImage;
    _userName.text = mobileModel.fullName;
    LJPhone * phoneModel = mobileModel.phones.firstObject;
    
//    self.phoneNumLabel.text = phoneModel.phone;
    
    if ([mobileModel.firend_type isEqualToString:@"yes"]) {
        
        [_invitationBtn setTitle:@"已添加" forState:UIControlStateNormal];
        [_invitationBtn setTitleColor:KHEXCOLOR(kGrayColor_66) forState:UIControlStateNormal];
        _invitationBtn.backgroundColor=[UIColor clearColor];
        
    }else
    {
        [_invitationBtn setTitle:@"邀请" forState:UIControlStateNormal];
        _invitationBtn.backgroundColor=KHEXCOLOR(@"#2DC076");
        
    }
}
-(void)didSelecdInvitationBtnAction
{
    if (self.selecdBlock) {
        self.selecdBlock(_index_row);
    }
    
    AAIMLog(@"");
    
}
#pragma mark好友同意
-(void)didSelecdAgreedBtnAction
{
    if ([self.delegate respondsToSelector:@selector(FirendsTableViewCellWithClickSelecdCell:)]) {
        [self.delegate FirendsTableViewCellWithClickSelecdCell:self];
    }
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
